/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.converter;

import br.com.foxline.model.TypeStamp;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author roniere
 */
@FacesConverter(value="typestampconverter")
public class TypeStampConverter implements Converter{

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        TypeStamp typeStamp = new TypeStamp();
        try{
        typeStamp.setId(Long.parseLong(value));
        }catch(Exception e){
            return null;
        }
        return typeStamp;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        TypeStamp typeStamp = (TypeStamp) value;
        return typeStamp.getId()+"";
    }
    
}
